<template>
	<view class="main">
		<bai-calendar @init="dateInit" @change="change"></bai-calendar>
		<view class="list_warp">
			<gui-empty v-if="dataList.length <= 0">
				<view slot="img" class="gui-flex gui-rows gui-justify-content-center">
					<!-- 请根据您的项目要求制作并更换为空图片 -->
					<image class="gui-empty-img"
						src="@/static/noImg.png">
					</image>
				</view>
				<text slot="text" class="gui-text-small gui-block-text gui-text-center gui-margin-top"
					style="color:#9DABFF;">暂无数据</text>
			</gui-empty>
			<view class="item gui-flex gui-align-items-center gui-space-between" @click="jumpDetail(item)" v-for="(item,index) in dataList" :key="index">
				<view class="label">
					{{item.title}}
				</view>
				<view class="time_status">
					<text class="status" v-if="item.state == 2">已取消</text>
					<text class="status" v-if="item.state == 1">已完成</text>
					<text class="time" v-if="item.state == 0">{{item.date.substring(11,16)}} 开始</text>
				</view>
				<view class="new_icon" v-if="index == dataList.length - 1 && item.state == 0">
					新
				</view>
			</view>
			<!-- <view class="item gui-flex gui-align-items-center gui-space-between">
				<view class="label">
					项目文档评审
				</view>
				<view class="time_status">
					<text class="status">已取消</text>
				</view>
			</view>
			<view class="item gui-flex gui-align-items-center gui-space-between">
				<view class="label">
					部门早会
				</view>
				<view class="time_status">
					<text class="time">09:30~09:40</text>
				</view>
			</view>
			<view class="item gui-flex gui-align-items-center gui-space-between">
				<view class="label">
					客户洽谈
				</view>
				<view class="time_status">
					<text class="time">09:30~09:40</text>
				</view>
				<view class="new_icon">
					新
				</view>
			</view>
			<view class="item gui-flex gui-align-items-center gui-space-between">
				<view class="label">
					会议复盘
				</view>
				<view class="time_status">
					<text class="time">09:30~09:40</text>
				</view>
			</view> -->
		</view>
		<bai-drag-button @btnClick="jumpAdd"></bai-drag-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				date: '',
				dataList: []
			}
		},
		onLoad() {
			uni.$on('updateBacklog', () => {
				this.loadData();
			})
		},
		onUnload() {
			uni.$off('updateBacklog');
		},
		methods: {
			change(e) {
				console.log(e);
				this.date = e.fulldate;
				this.loadData();
			},
			dateInit(e) {
				console.log(e);
				this.date = e;
				this.loadData();
			},
			loadData() {
				this.$api.getBacklog({
					date: this.date
				}).then(res => {
					this.dataList = res.data;
				})
			},
			jumpAdd() {
				this.$u.to(`/pages/toDoList/add?time=${this.date}`)
			},
			jumpDetail(item) {
				this.$u.to(`/pages/toDoList/detail?id=${item.id}&time=${this.date}`)
			},
		}
	}
</script>

<style lang="scss">
	page, .main {
		background-color: #f7f9fb;
	}
	.list_warp {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 66rpx;
		
		.item {
			overflow: hidden;
			position: relative;
			width: 686rpx;
			min-height: 100rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			padding: 0 24rpx;
			font-size: 24rpx;
			color: #0A0A0D;
			
			.time {
				color: #0E6EFF;
			}
			
			.new_icon {
				position: absolute;
				right: -55rpx;
				top: -50rpx;
				width: 100rpx;
				height: 100rpx;
				border-radius: 50rpx;
				color: #FFFFFF;
				background-color: #FB6547;
				font-size: 20rpx;
				line-height: 145rpx;
				padding-left: 20rpx;
			}
		}
	}
	
</style>